using KnowledgeQA.Models.DTOs;

namespace KnowledgeQA.Services.Interfaces
{
    /// <summary>
    /// 问答服务接口
    /// </summary>
    public interface IQAService
    {
        /// <summary>
        /// 单轮问答
        /// </summary>
        /// <param name="request">问答请求</param>
        /// <returns>问答响应</returns>
        Task<AskQuestionResponse> AskQuestionAsync(AskQuestionRequest request);

        /// <summary>
        /// 创建聊天会话
        /// </summary>
        /// <param name="request">创建请求</param>
        /// <returns>会话信息</returns>
        Task<ChatSessionDTO> CreateSessionAsync(CreateSessionRequest request);

        /// <summary>
        /// 获取会话列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <returns>会话列表</returns>
        Task<PagedResponse<ChatSessionDTO>> GetSessionsAsync(string? userId = null, int pageIndex = 1, int pageSize = 20);

        /// <summary>
        /// 根据ID获取会话
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <returns>会话信息</returns>
        Task<ChatSessionDTO?> GetSessionByIdAsync(int sessionId);

        /// <summary>
        /// 删除会话
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <returns>是否成功</returns>
        Task<bool> DeleteSessionAsync(int sessionId);

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="request">发送请求</param>
        /// <returns>消息信息</returns>
        Task<ChatMessageDTO> SendMessageAsync(SendMessageRequest request);

        /// <summary>
        /// 获取会话消息列表
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <returns>消息列表</returns>
        Task<PagedResponse<ChatMessageDTO>> GetSessionMessagesAsync(int sessionId, int pageIndex = 1, int pageSize = 50);

        /// <summary>
        /// 提交用户反馈
        /// </summary>
        /// <param name="request">反馈请求</param>
        /// <returns>是否成功</returns>
        Task<bool> SubmitFeedbackAsync(UserFeedbackRequest request);

        /// <summary>
        /// 导出会话记录
        /// </summary>
        /// <param name="sessionId">会话ID</param>
        /// <param name="format">导出格式（json、txt、csv）</param>
        /// <returns>导出内容</returns>
        Task<string> ExportSessionAsync(int sessionId, string format = "json");

        /// <summary>
        /// 获取问答统计信息
        /// </summary>
        /// <returns>统计信息</returns>
        Task<QAStats> GetQAStatsAsync();
    }

    /// <summary>
    /// 问答统计信息
    /// </summary>
    public class QAStats
    {
        /// <summary>
        /// 总会话数
        /// </summary>
        public int TotalSessions { get; set; }

        /// <summary>
        /// 总消息数
        /// </summary>
        public int TotalMessages { get; set; }

        /// <summary>
        /// 今日会话数
        /// </summary>
        public int TodaySessions { get; set; }

        /// <summary>
        /// 今日消息数
        /// </summary>
        public int TodayMessages { get; set; }

        /// <summary>
        /// 平均响应时间（毫秒）
        /// </summary>
        public double AverageResponseTime { get; set; }

        /// <summary>
        /// 用户满意度评分
        /// </summary>
        public double UserSatisfactionScore { get; set; }

        /// <summary>
        /// 按模型统计使用情况
        /// </summary>
        public Dictionary<string, int> UsageByModel { get; set; } = new Dictionary<string, int>();
    }
} 